var editorApp = angular.module('reportEditor', ['utilsModule']);
editorApp.controller('dataController', function($scope, $http, utilsService) {
    /** ingore tempararily
    //获取当前数据的HTML源码
    $scope.getData = function() {
        var data = CKEDITOR.instances.eidtorDemo.getData();
        if (data.length !== 0) {
            alert(data);
        } else {
            alert("无数据！");
        }
    };
    */
    //保存数据
    $scope.saveData = function() {
        var richText = CKEDITOR.instances.eidtorDemo.getData();
        if (richText.length !== 0) {
            if (document.querySelector("input[type='month']").value == "") {
                $(".text-danger").fadeIn(2000, function() {
                    $(".text-danger").text("请输入有效日期!!!");
                }).fadeOut(2000);
            } else {
                $http({
                    headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
                    url: "../../api/processQualityReport/richEditor.php",
                    data: $.param({
                        "part": utilsService.GetRequestParams().part,
                        "richText": richText,
                        "descDate": document.querySelector("input[type='month']").value
                    }),
                    method: 'POST'
                }).then(function successFn(response) {
                    if (response.data.error.returnCode == 0) {
                        $(".text-success").fadeIn(2000, function() {
                            $(".text-success").text(response.data.error.returnMessage);
                        }).fadeOut(2000);
                    } else {
                        $(".text-warning").fadeIn(2000, function() {
                            $(".text-warning").text(response.data.error.returnMessage);
                        }).fadeOut(2000);
                    }

                }, function failFn(response) {
                    $(".text-danger").fadeIn(2000, function() {
                        $(".text-danger").text(response.data.error.returnMessage);
                    }).fadeOut(2000);
                });
            }


        } else {
            $(".text-danger").fadeIn(2000, function() {
                $(".text-danger").text("请输入文本或HTML源码!");
            }).fadeOut(2000);
        }
    };
    //预览
    $scope.previewData = function() {
        document.querySelector(".preview").innerHTML = CKEDITOR.instances.eidtorDemo.getData();
    };

});